﻿using System.Net;
using Azure.Online.Proxy.Server;

namespace Azure.Online.Proxy.Actions {
    public class DownloadActionResult : ProxyActionResult {
        private readonly string _fileName;

        public DownloadActionResult(HttpWebResponse response, string fileName)
            : base(response) {
            _fileName = fileName;
        }

        public string ContentType { get; set; }

        protected override void RegisterHeaders(HttpServerResponse response) {
            base.RegisterHeaders(response);

            if (!string.IsNullOrWhiteSpace(ContentType)) {
                response.ContentType = ContentType;
            }
            if (!string.IsNullOrWhiteSpace(_fileName)) {
                response.Headers["Content-Disposition"] = "attachment; filename=" + _fileName;
            }

        }
    }
}